<template>
	<view class="orders">
		<scroll-view class="scroll-view_H" scroll-x="true">
			<view class="slide_type_list">
				<view class="slide_type_list_view" v-for="(item,index) in typeList" :key="index"
					:class="{is_selected:active==index}" @click="changeType(item,index)">
					<view>{{item.name}}</view>
				</view>
			</view>
		</scroll-view>

		<view class="rules" @click="goRuleDetail">
			<text>使用规则</text>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y" :scroll-y="true" :refresher-enabled="true"
			:refresher-threshold="45" refresher-background="#EFF0F1" @refresherrefresh="onRefresh"
			:refresher-triggered="refresh">
			<view class="content" v-for="(item,index) in ticketList" :key="item.id" :class="{'opmask':active != 0}">
				<view class="single_left">
					<view class="name offset" v-if="item.type == '1'">
						¥ {{item.offset_value}}
					</view>
					<view class="name" v-else-if="item.type == '2'">
						免保证金
					</view>
					<text v-if="item.type == '2'">免保证金券</text>
				</view>
				<view class="single_right">
					<view class="desc">
						{{item.title}} <text
							v-if="item.type == '1'">(满{{item.action_value}}减{{item.offset_value}})</text>
					</view>

					<view class="times">
						{{item.begin_date}} 至 {{item.expiration_date}}
					</view>
					<image class="used_img" v-if="active == 1" :src="IMGLink+'/my/used_img.png'" mode="widthFix">
					</image>
					<view class="zone">
						{{item.scope_title}}<text v-if="item.appoint_title">({{item.appoint_title}})</text>
					</view>
				</view>
			</view>

			<view v-show="isLoadMore && ticketList.length >0">
				<uni-load-more :status="loadStatus"></uni-load-more>
			</view>

			<view class="nodata" v-if="ticketList.length == 0">
				<image class="empty_img" :src="IMGLink+'/my/empty.png'" mode="widthFix"></image>
				<view>没有你想要的内容</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		addresslist
	} from '@/api/my/address.js';
	export default {
		data() {
			return {
				IMGLink: this.IMGLink,
				active: 0,
				typeList: [{
					name: '未过期'
				}, {
					name: '已使用'
				}, {
					name: '已过期'
				}],
				ticketList: [],
				page: 1, //页码
				size: '10',
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				refresh: false, // 下拉刷新标示
				status: "1", //1:未使用 2:已使用 3:过期 不传或传空:全部

			}
		},
		onLoad() {
			this.getDataList();
		},
		methods: {
			getDataList() {
				uni.showLoading({
					title: '加载中'
				});
				addresslist('getUserCouponsList', {
					page: this.page,
					page_size: this.size,
					status: this.status,
				}).then(res => {
					let datas = res.data.list;

					this.ticketList = this.page == 1 ? datas : this.ticketList.concat(datas);
					if (datas.length < this.size) { //小于size数，停止请求
						this.isLoadMore = true;
						this.loadStatus = 'nomore';
					} else {
						this.isLoadMore = false;
					}
					uni.hideLoading();

					this.refresh = false;
				}).catch(error => {
					uni.hideLoading();
					this.isLoadMore = false;
				})
			},
			changeType(item, index) {
				this.active = index;
				this.status = Number(index) + 1;
				this.page = 1;
				this.ticketList = [];
				this.getDataList();
			},

			onRefresh() {
				this.refresh = true;
				this.page = 1;
				this.getDataList();
			},
			onReachBottom() {
				if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
					this.isLoadMore = true;
					this.page++;
					this.getDataList();
				}
			},
			goRuleDetail() {
				uni.navigateTo({
					url: '/pagesA/my/rules/ruleDetail?type=10'
				})
			},

		}
	}
</script>
<style>
	page {
		background-color: #EFF0F1;
	}
</style>
<style lang="scss" scoped>
	@import "../my.scss";

	// 横向滑动tab
	.scroll-view_H {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		//#ifdef H5
		    top: 40px;
		//#endif
		z-index: 11;
		background-color: #FFFFFF;

		.slide_type_list {
			display: flex;
			padding: 20upx 30upx;

			.slide_type_list_view {
				width: 33%;
				padding-bottom: 10rpx;
				font-size: 28rpx;
				color: #0B0B0D;
				margin-right: 30rpx;

				view {
					text-align: center;
				}
			}

			.is_selected {
				color: #F54642;
				font-weight: 500;
				position: relative;
			}

			.is_selected:before {
				content: '';
				position: absolute;
				width: 44rpx;
				height: 8rpx;
				left: 50%;
				margin-left: -24rpx;
				bottom: -14rpx;
				background-color: #F54642;
			}
		}
	}

	.scroll-Y {
		// height: 90vh;
	}

	.rules {
		color: #7E7E7E;
		font-size: 26rpx;
		margin: 110rpx 26rpx 10rpx;
	}

	.opmask {
		opacity: .6;
	}

	.content {
		box-sizing: border-box;
		width: 94%;
		height: 224rpx;
		background: #FBF7F7;
		@include bck_img($img-link+"/my/coupon_bg.png");

		margin: 26rpx 3%;
		@include flexLayout(center, flex-start);

		.single_left {
			width: 30%;
			height: 100%;
			background-color: #F9EFEF;
			border-right: 2rpx dashed #F0E3E4;
			color: #F54642;
			font-size: 24rpx;
			@include flexLayout(center, center);
			flex-direction: column;

			.name {
				line-height: 56rpx;
				color: #F54642;
				font-size: 36rpx;
			}

			.offset {
				font-size: 52rpx;
				font-weight: bold;
			}
		}

		.single_right {
			position: relative;
			width: 70%;
			height: 100%;
			color: #0B0B0D;
			font-size: 28rpx;
			padding-top: 60rpx;

			.used_img {
				position: absolute;
				right: 10rpx;
				top: 50rpx;
				width: 116rpx;
			}

			.desc {
				font-weight: 500;
			}

			.times {
				color: #6B6B6B;
				font-size: 24rpx;
				margin: 14rpx 0 30rpx;
			}

			.times,
			.desc,
			.zone {
				padding-left: 40rpx;
			}

			.zone {
				line-height: 70rpx;
				border-top: 2rpx dashed #F0E3E4;
				color: #6B6B6B;
				font-size: 24rpx;
			}
		}
	}

	.nodata {
		text-align: center;
		color: #7D7D7D;
		font-size: 24rpx;
		margin-top: 50%;

		.empty_img {
			width: 468rpx;
		}
	}
</style>
